package chapt01;

public class Number{
	private String n_surname, n_name, n_age;
	public Number(){
		this.n_surname = "";
		this.n_name = "";
		this.n_age = "";
	}
 	public Number (String s_surname, String s_name, String s_age){
		this.n_surname = s_surname;
		this.n_name = s_name;
		this.n_age = s_age;
	}
	public String toString(){//склеивает элементы в строку
		return n_surname +" "+ n_name+ " " + n_age + "\n";
	}
	public Number fromString(String s){ //делит строку на 3 елемента
		int k = 0; int i = 0;
        Number tmp=new Number();
		for (int j = 0; j < s.length(); j++) {
            if (s.charAt(j) == ' ') {
                if (j > i) {
                	switch (k){
                	case 0 : tmp.setSurName(s.substring(i, j));
                	k++; break;
                	case 1 : tmp.setName(s.substring(i, j));
                	k++; break;
                	case 2 : tmp.setAge(s.substring(i, j));
                	k++; break;
                	default: break;
                	}
                }
                i = j + 1;
            }
        }
        if (i < s.length()) {
        	switch (k){
        	case 0 : tmp.setSurName(s.substring(i));
        	k++; break;
        	case 1 : tmp.setName(s.substring(i));
        	k++; break;
        	case 2 : tmp.setAge(s.substring(i));
        	k++; break;
        	default: break;
        	}
        }
        return tmp;
	}
	public String getSurName(){
		return this.n_surname; 
	}
	public String getName(){
		return this.n_name; 
	}
	public String getAge(){
		return this.n_age; 
	}
	public void setSurName(String s_surname){
		this.n_surname = s_surname;
	}
	public void setName(String s_name){
		this.n_name = s_name;
	}
	public void setAge(String s_age){
		this.n_age = s_age;
	}

}
